All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.JViewport
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----com.sun.java.swing.JComponent
|
+----com.sun.java.swing.JViewport
- public class JViewport
- extends JComponent
- implements Accessible
The "viewport" or "porthole" through which you see the underlying
information. When you scroll, what moves is the viewport. Its like
peering through a camera's viewfinder. Moving the viewfinder upwards
brings new things into view at the top of the picture and loses
things that were at the bottom.
Warning: serialized objects of this class will not be compatible with
future swing releases. The current serialization support is appropriate
for short term storage or RMI between Swing1.0 applications. It will
not be possible to load serialized Swing1.0 objects with future releases
of Swing. The JDK1.2 release of Swing will be the compatibility
baseline for the serialized form of Swing objects.
- See Also:
- JScrollPane
-
backingStore
-
True when this viewport is maintaining an offscreen image of its
contents, so that some scrolling can take place using fast "bit-blit"
operations instead of by accessing the view object to construct the
display.
-
backingStoreImage
- The view image used for a backing store.
-
isViewSizeSet
- True when the viewport dimensions have been determined.
-
lastPaintPosition
- The last viewPosition that we've painted, so we know how
much of the backing store image is valid.
-
scrollUnderway
- The scrollUnderway flag is used for components like JList.
-
JViewport()
- Create a JViewPort
-
addChangeListener(ChangeListener)
- Add a ChangeListener to the list that's notified each time the view's
size, position, or the viewport's extent size has changed.
-
addImpl(Component, Object, int)
- Sets the Viewport's one lightweight child, which can be null.
-
computeBlit(int, int, Point, Point, Dimension, Rectangle)
- Computes the parameters for a blit where the backing store image
currently contains oldLoc in the upper left hand corner
and we're scrolling to newLoc.
-
createLayoutManager()
- Subclassers can override this to install a different
layout manager (or null) in the constructor.
-
createViewListener()
- Create a listener for the view.
-
fireStateChanged()
-
-
getAccessibleContext()
- Get the AccessibleContext associated with this JComponent
-
getExtentSize()
- Returns the size of the visible part of the view in view coordinates.
-
getInsets()
- Returns the insets (border) dimensions as (0,0,0,0), since borders
are not supported on a JViewPort.
-
getView()
- Returns the Viewport's one child or null.
-
getViewPosition()
- Returns the view coordinates that appear in the upper left
hand corner of the viewport, 0,0 if there's no view.
-
getViewRect()
- Return a rectangle whose origin is getViewPosition and size is
getExtentSize().
-
getViewSize()
- If the view's size hasn't been explicitly set, return the
preferred size, otherwise return the view's current size.
-
isBackingStoreEnabled()
- Returns true if this viewport is maintaining an offscreen
image of its contents.
-
isOptimizedDrawingEnabled()
- The JViewport overrides the default implementation of
this method (in JComponent) to return false.
-
paint(Graphics)
- Depending on whether the backingStore is enabled,
either paint the image through the backing store or paint
just the recently exposed part, using the backing store
to "blit" the remainder.
-
remove(Component)
- Removes the Viewport's one lightweight child.
-
removeChangeListener(ChangeListener)
- Remove a ChangeListener from the list that's notified each
time the views size, position, or the viewports extent size
has changed.
-
repaint(long, int, int, int, int)
-
We always repaint in our parent coordinate system to make sure
only one paint is performed by the RepaintManager.
-
scrollRectToVisible(Rectangle)
- Overridden to scroll the view so that Rectangle within the
view becomes visible.
-
setBackingStoreEnabled(boolean)
- If true if this viewport will maintain an offscreen
image of its contents.
-
setBorder(Border)
- The viewport "scrolls" it's child (called the "view") by the
normal parent/child clipping (typically the view is moved in
the opposite direction of the scroll).
-
setBounds(int, int, int, int)
-
Sets the bounds of this viewport.
-
setExtentSize(Dimension)
- Set the size of the visible part of the view using view coordinates.
-
setView(Component)
- Sets the Viewport's one lightweight child (
view
),
which can be null.
-
setViewPosition(Point)
- Sets the view coordinates that appear in the upper left
hand corner of the viewport, null if there's no view.
-
setViewSize(Dimension)
- Sets the view coordinates that appear in the upper left
hand corner of the viewport, and the size of the view.
-
toViewCoordinates(Dimension)
- Convert a size in pixel coordinates to view coordinates.
-
toViewCoordinates(Point)
- Convert a point in pixel coordinates to view coordinates.
isViewSizeSet
protected boolean isViewSizeSet
- True when the viewport dimensions have been determined.
lastPaintPosition
protected Point lastPaintPosition
- The last viewPosition that we've painted, so we know how
much of the backing store image is valid.
backingStore
protected boolean backingStore
- True when this viewport is maintaining an offscreen image of its
contents, so that some scrolling can take place using fast "bit-blit"
operations instead of by accessing the view object to construct the
display.
backingStoreImage
protected transient Image backingStoreImage
- The view image used for a backing store.
scrollUnderway
protected boolean scrollUnderway
- The scrollUnderway flag is used for components like JList.
When the downarrow key is pressed on a JList and the selected
cell is the last in the list, the scrollpane autoscrolls.
Here, the old selected cell needs repainting and so we need
a flag to make the viewport do the optimised painting
only when there is an explicit call to setViewPosition(Point).
When setBounds() is called through other routes,
the flag is off and the view repaints normally.
Another approach would be to remove this from the Viewport
class and have the JList manage this case by using
setBackingStoreEnabled().
JViewport
public JViewport()
- Create a JViewPort
addImpl
protected void addImpl(Component child,
Object constraints,
int index)
- Sets the Viewport's one lightweight child, which can be null.
(Since there is only one child which occupies the entire viewport,
the constraints and index arguments are ignored.)
- Parameters:
- child - the Component ______________
- constraints - the Object ______________
- index - the int ______________
- Overrides:
- addImpl in class Container
- See Also:
- setView
remove
public void remove(Component child)
- Removes the Viewport's one lightweight child.
- Overrides:
- remove in class Container
- See Also:
- setView
scrollRectToVisible
public void scrollRectToVisible(Rectangle contentRect)
- Overridden to scroll the view so that Rectangle within the
view becomes visible.
- Parameters:
- contentRect - the Rectangle to display
- Overrides:
- scrollRectToVisible in class JComponent
setBorder
public final void setBorder(Border border)
- The viewport "scrolls" it's child (called the "view") by the
normal parent/child clipping (typically the view is moved in
the opposite direction of the scroll). A non-null border,
or non-zero insets, isn't supported, to prevent the geometry
of this component from becoming complex enough to inhibit
subclassing. To create a JViewport with a border, add it to a
JPanel that has a border.
- Parameters:
- border - the Border to set
- Overrides:
- setBorder in class JComponent
getInsets
public final Insets getInsets()
- Returns the insets (border) dimensions as (0,0,0,0), since borders
are not supported on a JViewPort.
- Returns:
- new Insets(0, 0, 0, 0)
- Overrides:
- getInsets in class JComponent
- See Also:
- setBorder
isOptimizedDrawingEnabled
public boolean isOptimizedDrawingEnabled()
- The JViewport overrides the default implementation of
this method (in JComponent) to return false. This ensures
that the drawing machinery will call the Viewport's paint()
implementation rather than messaging the JViewport's
children directly.
- Returns:
- false
- Overrides:
- isOptimizedDrawingEnabled in class JComponent
paint
public void paint(Graphics g)
- Depending on whether the backingStore is enabled,
either paint the image through the backing store or paint
just the recently exposed part, using the backing store
to "blit" the remainder.
The term "blit" is the pronounced version of the PDP-10
BLT (BLock Transfer) instruction, which copied a bunch of
bits. (In case you were curious.)
- Parameters:
- g - the Graphics context within which to paint
- Overrides:
- paint in class JComponent
setBounds
public void setBounds(int x,
int y,
int w,
int h)
- Sets the bounds of this viewport.
- Parameters:
- x - an int giving distance from left in pixels
- y - an int giving distance from top in pixels
- w - an int giving width in pixels
- h - an int giving height in pixels
- Overrides:
- setBounds in class Component
- See Also:
- setBounds
isBackingStoreEnabled
public boolean isBackingStoreEnabled()
- Returns true if this viewport is maintaining an offscreen
image of its contents.
setBackingStoreEnabled
public void setBackingStoreEnabled(boolean x)
- If true if this viewport will maintain an offscreen
image of its contents. The image is used to reduce the cost
of small one dimensional changes to the viewPosition.
Rather than repainting the entire viewport we use
Graphics.copyArea() to effect some of the scroll.
getView
public Component getView()
- Returns the Viewport's one child or null.
- See Also:
- setView
setView
public void setView(Component view)
- Sets the Viewport's one lightweight child (
view
),
which can be null.
- See Also:
- getView
getViewSize
public Dimension getViewSize()
- If the view's size hasn't been explicitly set, return the
preferred size, otherwise return the view's current size.
If there is no view, return 0,0.
- Returns:
- a Dimension object specifying the size of the view
setViewSize
public void setViewSize(Dimension newSize)
- Sets the view coordinates that appear in the upper left
hand corner of the viewport, and the size of the view.
- Parameters:
- newSize - a Dimension object specifying the size and
location of the new view coordinates, or null if there
is no view
getViewPosition
public Point getViewPosition()
- Returns the view coordinates that appear in the upper left
hand corner of the viewport, 0,0 if there's no view.
- Returns:
- a Point object giving the upper left coordinates
setViewPosition
public void setViewPosition(Point p)
- Sets the view coordinates that appear in the upper left
hand corner of the viewport, null if there's no view.
- Parameters:
- p - a Point object giving the upper left coordinates
getViewRect
public Rectangle getViewRect()
- Return a rectangle whose origin is getViewPosition and size is
getExtentSize(). This is the visible part of the view, in view
coordinates.
- Returns:
- a Rectangle giving the visible part of the view using view coordinates.
computeBlit
protected boolean computeBlit(int dx,
int dy,
Point blitFrom,
Point blitTo,
Dimension blitSize,
Rectangle blitPaint)
- Computes the parameters for a blit where the backing store image
currently contains oldLoc in the upper left hand corner
and we're scrolling to newLoc. The parameters are modified
to return the values required for the blit.
getExtentSize
public Dimension getExtentSize()
- Returns the size of the visible part of the view in view coordinates.
- Returns:
- a Dimension object giving the size of the view
toViewCoordinates
public Dimension toViewCoordinates(Dimension size)
- Convert a size in pixel coordinates to view coordinates.
Subclasses of viewport that support "logical coordinates"
will override this method.
- Parameters:
- size - a Dimension object using pixel coordinates
- Returns:
- a Dimension object converted to view coordinates
toViewCoordinates
public Point toViewCoordinates(Point p)
- Convert a point in pixel coordinates to view coordinates.
Subclasses of viewport that support "logical coordinates"
will override this method.
- Parameters:
- p - a Point object using pixel coordinates
- Returns:
- a Point object converted to view coordinates
setExtentSize
public void setExtentSize(Dimension newExtent)
- Set the size of the visible part of the view using view coordinates.
- Parameters:
- newExtent - a Dimension object specifying the size of the view
createViewListener
protected JViewport. ViewListener createViewListener()
- Create a listener for the view.
- Returns:
- a ViewListener
createLayoutManager
protected LayoutManager createLayoutManager()
- Subclassers can override this to install a different
layout manager (or null) in the constructor. Returns
a new JViewportLayout object.
- Returns:
- a LayoutManager
addChangeListener
public void addChangeListener(ChangeListener l)
- Add a ChangeListener to the list that's notified each time the view's
size, position, or the viewport's extent size has changed.
- Parameters:
- l - the ChangeListener to add
- See Also:
- removeChangeListener, setViewPosition, setViewSize, setExtentSize
removeChangeListener
public void removeChangeListener(ChangeListener l)
- Remove a ChangeListener from the list that's notified each
time the views size, position, or the viewports extent size
has changed.
- Parameters:
- l - the ChangeListener to remove
- See Also:
- addChangeListener
fireStateChanged
protected void fireStateChanged()
repaint
public void repaint(long tm,
int x,
int y,
int w,
int h)
- We always repaint in our parent coordinate system to make sure
only one paint is performed by the RepaintManager.
- Parameters:
- tm - maximum time in milliseconds before update
- x - the x coordinate (pixels over from left)
- y - the y coordinate (pixels down from top)
- width - the width
- height - the height
- Overrides:
- repaint in class JComponent
- See Also:
- update
getAccessibleContext
public AccessibleContext getAccessibleContext()
- Get the AccessibleContext associated with this JComponent
- Returns:
- the AccessibleContext of this JComponent
- Overrides:
- getAccessibleContext in class JComponent
All Packages Class Hierarchy This Package Previous Next Index